#!/usr/bin/python
#-*- coding:utf-8 -*-
# File Name: get_flatedecode_data.py
# Author: o0xmuhe
# Mail: o0xmuhe@gmail.com
# Created Time: 2018-05-19 14:52:26

import re
import zlib
import sys


def dump2file(out,data):
    with open(out,'wb') as f:
        f.write(data)

if len(sys.argv) != 3 :
    print ("error arguments!")
    sys.exit(1)

pdf = open(sys.argv[1], "rb").read()
stream = re.compile(r'.*?FlateDecode.*?stream(.*?)endstream', re.S)

for s in stream.findall(pdf):
    s = s.strip('\r\n')
    try:
        # print(zlib.decompress(s))
        dump2file(sys.argv[2],zlib.decompress(s))
        print("")
    except:
        pass
